package net.suncaper.demo.controller;

import net.suncaper.demo.domain.Order;
import net.suncaper.demo.domain.Hotel;
import net.suncaper.demo.domain.RoomType;
import net.suncaper.demo.service.HotelService;
import net.suncaper.demo.service.RoomTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;



@Controller
@RequestMapping("/hotel")
public class HotelController {
    @Autowired
    private HotelService hotelService;

    @Autowired
    private  RoomTypeService roomTypeService;

    @GetMapping("/searchCity")
    public String searchRegion(Model model){
        model.addAttribute("order", new Order());
        return "/pages/hotel/search_city.html";
    }
    @PostMapping("/searchCity")
    public  String searchHotel(@RequestParam("city")String city, Model model, HttpServletRequest request) {


//        String name= A+city+B;
        city="'%"+city+"%'";
//                System.out.println(city);
        Long cityID = hotelService.selectByCityName(city);
        HttpSession session=request.getSession();
        session.setAttribute("cityID",cityID);
        List<Hotel> hotels=hotelService.selectHotelFromCity(cityID);

        model.addAttribute("hotels", hotels);
        return "pages/hotel/hotel_list";
    }

    @GetMapping("/detail/{hotelid}")
    public String orderDetail(@PathVariable("hotelid") Long hotelid, Model model, HttpServletRequest request){
        HttpSession session=request.getSession();
        Long cityID;
        cityID= (Long)session.getAttribute("cityID");
        model.addAttribute("hotel", hotelService.selectByID(cityID,hotelid));
        return "/pages/hotel/hotel_detail.html";
    }

//
//    @PostMapping("/detail")
//    public  String saveOrder() {
//        return "redirect:/hotel/searchCity";
//    }


    }
